package logic

import (
	"context"
	"doc-register/model"
	"gorm.io/gorm"

	"doc-register/userrpc/internal/svc"
	"doc-register/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocAddLogic {
	return &DocAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DocAddLogic) DocAdd(in *userrpc.DocAddRequest) (*userrpc.DocAddResponse, error) {
	// todo: add your logic here and delete this line
	doc := model.Doc{
		Model:   gorm.Model{},
		Name:    in.Name,
		Title:   in.Title,
		Types:   in.Types,
		CarNum:  in.CarNum,
		Number:  in.Number,
		VxName:  in.VxName,
		Phone:   in.Phone,
		Address: in.Address,
	}
	model.DB.Create(&doc)
	return &userrpc.DocAddResponse{
		DocId:   int64(doc.ID),
		Name:    doc.Name,
		Title:   doc.Title,
		Types:   doc.Types,
		CarNum:  doc.CarNum,
		Number:  doc.Number,
		VxName:  doc.VxName,
		Phone:   doc.Phone,
		Address: doc.Address,
	}, nil
}
